﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.Common;
using System.Configuration;
using NLog;

namespace Vit.Data
{
    public class DbConnectionVisitorBase : IDbConnectionVisitor
    {
        protected virtual string[] VisitingConnectionStringNames
        {
            get { return null; }
        }

        #region IDbConnectionVisitor Members

        public virtual bool IsVisiting(DbConnectionWrapper connectionWrapper)
        {
            if (VisitingConnectionStringNames != null)
            {
                foreach (string connStringName in VisitingConnectionStringNames)
                {
                    var connSetting = ConfigurationManager.ConnectionStrings[connStringName];
                    if (connSetting != null && String.Equals(connSetting.ConnectionString, connectionWrapper.ConnectionString, StringComparison.OrdinalIgnoreCase))
                        return true;
                }
                return false;
            }
            return true;
        }

        public virtual void OnConnectionStateChange(object sender, StateChangeEventArgs e)
        {
        }

        public virtual void OnCommandExecuting(object sender, CommandExecutionEventArgs e)
        {
        }

        public virtual void OnCommandExecuted(object sender, CommandExecutionEventArgs e)
        {
        }

        public virtual void OnCommandFailed(object sender, CommandExecutionEventArgs e)
        {
        }

        public virtual void OnTransactionCommit(object sender, TransactionEventArgs e)
        {
        }

        public virtual void OnTransactionRollback(object sender, TransactionEventArgs e)
        {
        }

        #endregion

        #region IProvider Members

        public virtual void Registering()
        {
        }

        public virtual void Registered()
        {
        }

        public virtual void Executing()
        {
        }

        public virtual void Executed()
        {
        }

        #endregion
    }
}
